package com.heima.big_event03.controller;

import com.heima.big_event03.entity.Category;
import com.heima.big_event03.entity.User;
import com.heima.big_event03.service.CategoryService;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
import com.heima.big_event03.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Category)表控制层
 *
 * @author makejava
 * @since 2025-03-04 20:44:22
 */
@RestController
@RequestMapping("category")
@Api("文章分类")
@Slf4j
@Validated//<--------开启注解校验
public class CategoryController {
    /**
     * 服务对象
     */
    @Resource
    private CategoryService categoryService;

    /**
     * 新增文章分类
     * @return
     */
    @PostMapping
    @ApiOperation("新增文章分类")
    public Result addCategory(@RequestBody Category category){
//        log.info("前端来的数据:"+category.getCategoryAlias());
        this.categoryService.add(category);
        return Result.success();
    }

    /**
     * 文章分类列表
     * @return
     */
    @GetMapping
    @ApiOperation("文章分类列表")
    public Result<List<Category>> getDatalist(){
        List<Category> list = this.categoryService.list();
//        log.info("返回的数据{}",list);
        return Result.success(list);
    }

    /**
     * 获取文章分类详情
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation("获取文章分类详情")
    public Result<Category> queryById(String id){
        Category c = this.categoryService.queryById(id);
        log.info("文章分类详情：{}",c);
        return  Result.success(c);
    }

    /**
     * 更新文章分类
     * @return
     */
    @PutMapping
    @ApiOperation("更新文章分类")
    public Result updateDetail(@RequestBody Category c){
        this.categoryService.update(c);

        return Result.success();
    }

    /**
     * 删除文章分类
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除文章分类")
    public Result deleteDetail(String id){
        boolean status = this.categoryService.deleteById(id);
        log.info("删除:{}",status);
        return Result.success();
    }



}

